﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplication1.App_Start
{
    public class CustomModule:IHttpModule
    {
        public void Dispose()
        {
            ;// throw new NotImplementedException();
        }

        public void Init(HttpApplication context)
        {
            context.PostResolveRequestCache += CustomPostResolveRequestCache;
        }

        private void CustomPostResolveRequestCache(object sender,EventArgs e)
        {
            var app = sender as HttpApplication;
            //在这里解析路由信息，根据不同的解析结果返回不同的 handler(这里就不详细实现了)

            var context = new HttpContextWrapper(app.Context);
           //解析路径，相当于路由
           var path = context.Request.AppRelativeCurrentExecutionFilePath;
           var routString = path.Substring(2).ToLower();
           context.RemapHandler(new CustomHttpHandler(routString));
        }
    }
}